#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)

typedef long long LL;

template<typename T>
inline T read() {
    T x;
    cin >> x;
    return x;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    // freopen("input.txt", "r", stdin);
    int n = read<int>();
    vector<int> a(n);
    int m(read<int>());
    FOR(i, 0, n)a[i] = read<int>();

    LL left = *max_element(a.begin(), a.end()), right = accumulate(a.begin(), a.end(), 0LL);
    LL best = right;
    while (left <= right) {
        LL mid = (left + right) / 2;
        LL tot = 0, s = 0;
        FOR(i, 0, n) {
            if (s + a[i] > mid) {
                s = a[i];
                ++tot;
            } else {
                s += a[i];
            }
        }
        if (s != 0) {
            ++tot;
        }
        if (tot > m) {
            left = mid + 1;
        } else {
            best = min(best, mid);
            right = mid - 1;
        }
    }
    cout << best << endl;


    return 0;
}